<?php
header("Content-Type: text/html; charset=iso-8859-1");
require 'include.php';
function clean_accent($chaine) {
	return html_entity_decode($chaine);
	return( strtr( $chaine,
	"ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ",
	"AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn" ) );
}
$text = (!empty($_REQUEST['value'])) ? ereg_replace("\[[0-9]*\]\ ","",$_REQUEST['value']) : "";
if($text){
	$no = (ereg("\[([0-9]*)\]\ ",$_REQUEST['value'],$regs)) ? $regs[1] : "";
}
else $no = "";
$check = (!empty($_REQUEST['check'])) ? $_REQUEST['check'] : "";
$print_map = (!empty($_REQUEST['map'])) ? $_REQUEST['map'] : "";
if($text){
	if($no) $q = "select * from salles where nom like '%$text%' and no = '$no' and no != 0";
	else $q = "select * from salles where nom like '%$text%' or no = '$text' and no != 0";
	$r = ExecRequete($q);
	if($print_map && $s = LigneSuivante($r)){
		$map = new GoogleMapAPI('map');
		$map->setDSN('mysql://root:mysql@localhost/vbcll_ch_-_vbcll2');
		$map->setAPIKey('ABQIAAAAi0BNTlPrlPLwBQAahU7EfxS19qvxCWvGKNPnyfjNhPRzYPvs4RQV3UBViqhZeclYzXSgUgBrycqjAw');
		$url = ($s->adresse) ? (clean_accent($s->adresse.", $s->localite, ")) : clean_accent("$s->nom, $s->localite, ");
		if($s->lon != '0.000000' && $s->lat != '0.000000' && $s->lon && $s->lat){
			$map->addMarkerByCoords($s->lon,$s->lat,$s->nom,"[$s->no] ".$s->nom);
		}
		else $map->addMarkerByAddress($url,"$s->nom","[$s->no] $s->nom");
        $map->setMapType('hybrid');
		$map->disableSidebar();
		

		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n";
		echo "<html xmlns='http://www.w3.org/1999/xhtml' xmlns:v='urn:schemas-microsoft-com:vml'>\n";
		echo "<head>\n";
		$map->printHeaderJS();
		$map->printMapJS();
		echo "<!-- necessary for google maps polyline drawing in IE -->\n";
		echo "<style type='text/css'>\n";
		echo "  v\:* {\n";
		echo "    behavior:url(#default#VML);\n";
		echo "  }\n";
		echo "</style>\n";
		echo "<title>VBCLL - salles</title>\n";		
		echo "<link rel='stylesheet' href='styles/vbcll.css' type = 'text/css' />\n";
		echo "<!--[if IE]";
		echo "<link rel='stylesheet' href='styles/vbcll_ie.css' type = 'text/css' />\n";
		echo "-->";
		echo "</head>\n";
		echo "<body onload='onLoad()' style = 'background-color: #fffacd;'>\n";
		echo "<h2>Salle [$s->no] $s->nom</h2>";
		#echo "<p class = 'center bold'>".(utf8_decode($s->adresse)).",  $s->localite</p>\n";
		echo "<p class = 'center bold'>".($s->adresse).",  $s->localite</p>\n";
		echo "<p class = 'center'>\n";
		$map->printMap();
		echo "</p>\n";
		$approx = (!ereg("[0-9]+",$s->adresse)) ? "ATTENTION: l'adresse n'est pas pr&eacute;cise. Le lieu marqu&eacute; est approximatif !!" : "";
		echo "<p class= 'center highlight'>$approx</p>\n";
		echo "</body>\n";
		echo "</html>\n";
		$map->printOnLoad();
	}
	else{
		if($check && mysql_num_rows($r) == 1){
			$s = LigneSuivante($r);
			echo $s->no;
		}
		elseif($check && mysql_num_rows($r) != 1){
			echo "";
		}
		elseif(mysql_num_rows($r)){
			echo "<ul>";
			while($s = LigneSuivante($r)){
				echo "<li>[".$s->no."] ".$s->nom."</li>";
			}
			echo "</ul>";
		}
		else echo "<ul><li>---</li></ul>";		
	}
}
else echo "<ul><li>---</li></ul>";
?>
